package com.project.weimi.utils;


import com.project.weimi.R;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.Button;

/**
 * 
 * @ClassName:TimeCount
 * @Description:倒计时的类 目前只是能传入Button，后期需要在扩展
 * @author ldf
 * @date 2016年2月26日下午5:41:28
 */
public class TimeCount extends CountDownTimer {
	private Button mView;

	private String text = "等待";
	private String finishText = "发送验证码";

	// 设置完成计时后显示在view上的文字
	public void setFinishText(String finishText) {
		this.finishText = finishText;
	}

	// 设置倒计时后面的文字
	public void setText(String text) {
		this.text = text;
	}

	public TimeCount(long millisInFuture, long countDownInterval, Button v) {
		super(millisInFuture, countDownInterval);
		this.mView = v;
	}

	@Override
	public void onTick(long millisUntilFinished) {
		if (mView instanceof Button) {
			mView.setClickable(false);
			mView.setBackgroundResource(R.drawable.selector_integralexchange_tv_bg2);
			mView.setTextColor(Color.parseColor("#C1BFBF"));
			mView.setTextSize(14);
			mView.setText(text + millisUntilFinished / 1000 + "秒");
		}
	}

	@Override
	public void onFinish() {
		if (mView instanceof Button) {
			mView.setClickable(true);
			mView.setBackgroundResource(R.drawable.selector_integralexchange_tv_bg);
			mView.setTextColor(Color.parseColor("#00B7EE"));
			mView.setTextSize(14);
			mView.setText(finishText);
		}
	}

}
